require('module-alias/register')

const Koa = require('koa')
const parser = require('koa-bodyparser')
const path = require('path')

const {accessLogger, systemLogger,} = require('./core/log4');// log4js
const staticCache = require('koa-static-cache')


// 初始化管理器
const InitManager = require('./core/init');
// 全局异常处理
const catchError = require('./middlewares/exception')
// koa静态资源
const koaStatic = require('koa-static')

const app = new Koa()

app.use(accessLogger()) // log4js
app.use(catchError)
app.use(parser())
app.use(koaStatic(path.join(__dirname, './static')))

app.use(staticCache(path.join(__dirname,'./static'),{
    maxAge:365*24*60*60 //1年
}))

app.on('error', err => {
    logger.error(err)
})

InitManager.initCore(app)

app.listen(3000)
